from google.appengine.ext import webapp
from google.appengine.ext import db
from google.appengine.ext.webapp.util import run_wsgi_app
import simplejson as json
from models import User

class user(webapp.RequestHandler):
    def post (self):
        
        objs = self.request.get('key')
#        json.dumps for json sent
#        self.response.out.write(objs) 
        
        exist = False
        dishes = db.GqlQuery("SELECT * from User")
        for rest in dishes:
            if rest.android_id == objs:
                exist = True
                break
        if not exist:
            user = User(android_id=objs)
            user.put()
#        self.response.out.write("r")         
        
application = webapp.WSGIApplication([('/add/user', user)],debug=True)
  
def main():
    run_wsgi_app(application)
    
if __name__ == "__main__":
    main()